@extends('layouts.admin')
@section('pageTitle', '活动列表')
@section('style')
    <style>
        .fixed-table-body{
            overflow: inherit;
        }
        .fixed-table-container thead th .desc,.fixed-table-container thead th .both,.fixed-table-container thead th .asc{
            background-position: left 5px;
        }
        .fixed-table-container thead th .sortable{
            padding-left: 30px;
        }
        .modal-dialog .modal-body video,.modal-dialog .modal-body img{
            width: auto;
            height: auto;
            max-height: 300px;
        }
        .img-container,.video-container{
            /*margin: 3px auto;*/
            width: 512px !important;
            height: 288px !important;
            background-color: #000;
        }
        .img-container img,.video-container video{
            display: block;
            margin: 0 auto;
            width: auto !important;
            max-height: 288px !important;
        }
        .video-container video{
            width:100% !important;
        }
        .card .header legend{
            margin-bottom: 0 !important;
        }
        @media (max-width: 992px){
            .main-panel .card legend, .wrapper-full-page .card legend{
                margin-bottom: 0;
            }
        }
    </style>
@endsection
@section('content')
    {{--@component('components.web.sidemenu')--}}
    {{--@endcomponent--}}
    <div class="main-panel" id="activity-list">
        <div class="content apartment-index">
            <div class="container-fluid" style="min-height:600px;">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="header">
                                <legend>活动列表</legend>
                            </div>
                            <div class="content">
                                <ul role="tablist" class="nav categoty-tab">
                                    {{--<li role="presentation"  data-value="{{\App\Models\Activity\Activity::ACTIVITY_CATEGORY_WECHAT}}" class="active">--}}
                                        {{--<a href="javascript:;" data-toggle="tab"aria-expanded="true">公众号H5</a>--}}
                                    {{--</li>--}}
                                    {{--<li class="active"  data-value="{{\App\Models\Activity\Activity::ACTIVITY_CATEGORY_H5}}" >--}}
                                    {{--<li class="active"  data-value="{{\App\Models\Activity\Activity::ACTIVITY_CATEGORY_H5}}" >--}}
                                        {{--<a href="javascript:;" data-toggle="tab"  aria-expanded="false">应用内H5</a>--}}
                                    {{--</li>--}}

                                </ul>
                                <div class="toolbar">
                                    {{--<select class="selectpicker categorySelect" data-style="btn-default btn-block" data-menu-style="dropdown-blue">--}}
                                        {{--<option value="1">公众号H5</option>--}}
                                        {{--<option value="2">应用内H5</option>--}}
                                    {{--</select>--}}
                                    <button class="btn btn-success add-btn" data-url="/web/activity/add">
                                        <i class="fa fa-plus"></i> 添加
                                    </button>
                                </div>

                                <table id="bootstrap-table-container" class="table" data-url="/web/activity/list?category=2" data-delete-url="/web/activity/delete">
                                    <thead>
                                    {{--<th data-field="state" data-checkbox="true"></th>--}}
                                    <th data-field="name" data-sortable="false">活动名称</th>
                                    <th data-field="weight" data-sortable="true">权重</th>
                                    <th data-field="created_at" data-sortable="true">创建日期</th>
                                    <th data-field="model.name" data-formatter="categoryFormatter" data-sortable="false">活动类型</th>
                                    <th data-field="startTime" data-formatter="timeFormatter" data-sortable="false">有效期</th>
                                    <th data-field="isPause" data-formatter="statusFormatter" data-sortable="false">状态</th>
                                    {{--<th data-field="shows" data-formatter="showsFormatter" data-sortable="false">浏览｜参与｜中奖</th>--}}
                                    <th data-field="actions" class="td-actions text-center" data-events="operateEvents" data-formatter="operateFormatter">操作</th>
                                    </thead>
                                    <tbody>

                                    </tbody>
                                </table>
                            </div>
                        </div><!--  end card  -->
                    </div> <!-- end col-md-12 -->
                </div> <!-- end row -->
            </div>
        </div>
    </div>
@endsection
@section('script')
    <script>
        function showsFormatter(value, row, index) {
            return row.clicks+'|'+row.joins+'|'+row.winnings;
        }
        function categoryFormatter(value,row) {
            return row.model.name;
        }
        function timeFormatter(value,row) {
            return row.startTime +'</br>'+row.endTime;
        }
        function statusFormatter(value,row) {
            var str = '';
            if (row.isPause == 1){
                str = '<span class="text-warning">已暂停</span>';
                return str;
            }
            if ( moment(row.endTime).unix()<moment().unix()){
                str = '<span class="text-danger">已结束</span>';
            }else if(moment(row.endTime).unix()>moment().unix() && moment(row.startTime).unix()<=moment().unix()){
                str = '<span class="text-success">进行中</span>';
            }else {
                str = '<span class="text-info">未开始</span>';
            }
            return str;
        }
        $('.categoty-tab li').on('click',function () {
            var value = $(this).data('value');
            $(this).parent().find('li').removeClass('active');
            $(this).addClass('active');
            $('#bootstrap-table-container').bootstrapTable('refreshOptions',{
                queryParams:function(params){
                    return $.extend(params,{'category':value});
                }
            })

        });
        $('#bootstrap-table-container').on('refresh.bs.table',function (params) {
            console.log('refresh table params'+params);
        });
        window.operateErollEvents={
            'click .enrollDetailsView':function(e,value,row){
                console.log(row);
                var groups = row.groups;
                var img_reg = new RegExp("<img","g");
                var video_reg = new RegExp("<video","g");
                value = value.replace(img_reg,'<img width="80%" ');
                value = value.replace(video_reg,'<video width="80%" ');
                var enrollContentModal = utils.modal('', function (ele) {
                    if(groups.length > 0){
                        var str = '<p>审核分组:';
                        var chk = '';
                        for(var i=0; i< groups.length; i++){

                            chk = (i==0)?'checked':'';

                            str += '<input style="margin-left: 10px;" '+chk+' type="radio" name="group"  data-rowstatus="'+row.status+'" data-rowid="'+row.id+'" data-groupid="'+groups[i]["id"]+'" />'+groups[i]["title"];
                        }
                        str += '</p>';
                        value = value+str;
                    }
                    ele.find('.modal-body').html(value);
                }, ['返回','审核'], function (res) {
                    if (res == 1) {
                        var groupObj = $('input:radio[name="group"]:checked');
                        if(groupObj.length == 0){
                            if(row.status == 1){
                                utils.showNotification('审核已通过，不可重复审核！',3);
                                return false;
                            }
                            var check_flag = {{\App\Models\Enroll\Enroll::CHECK_PASS}};
                            $.post('/web/enroll/edit',{groupid:groupid,id:row.id,act_id:act_id,status:check_flag},function (res) {
                                if (res.code == 0){
                                    utils.showNotification('操作成功',2);
                                    $('#validateEnrollTable').bootstrapTable('refresh');
                                }else {
                                    utils.showNotification(res.message,3);
                                }
                            })
                        }else{
                            checkGroup('input:radio[name="group"]:checked');
                        }
                        //act_id = row.id;
                        var validateEnrollModal = utils.modal('审核报名项', function (ele) {
                            var html =  '<table class="table" id="validateEnrollTable"><thead><tr>' +
                                '<th data-field="" data-checkbox="true">选择</th>' +
                                '<th data-field="name" class="text-center">姓名</th>' +
                                //                                '<th data-field="contents" class="text-center" data-formatter="enrollContentsFormatter" data-events="operateErollEvents">内容</th>' +
                                '<th data-field="mobile" class="text-center">手机号</th>' +
                                '<th data-field="created_at" class="text-center">时间</th>' +
                                '<th data-field="details" class="text-center" data-formatter="enrollDetailsFormatter" data-events="operateErollEvents">详情</th>' +
                                '<th data-field="status" data-formatter="enrollStatusFormatter" class="text-center">状态</th>' +
                                '<th data-field="validateActions" class="text-center" data-formatter="enrollValidateFormatter" data-events="operateErollEvents">审核</th>' +
                                '</tr></thead></table>';
                            ele.find('.modal-body').html(html);
                            var enroll_table_option = {
                                toolbar:false,
                                search:false,
                                pagination: true,
                                sidePagination:'server',
                                pageSize:4,
                                showRefresh:false,
                                contentType: "application/x-www-form-urlencoded",
                                queryParams: function (query) {
                                    query['activities_id'] = act_id;
                                    return query;
                                },
                                url: '/web/enroll/list',
                            };

                            default_table_option = $.extend(default_table_option, enroll_table_option);
                            $('#validateEnrollTable').bootstrapTable(default_table_option);
                        }, ['确认'], function (res) {
                            if (res == 1) {
                                validateEnrollModal.modal('hide');
                            }
                        });
//                        enrollContentModal.modal('hide');
                    }else if(res == 0){
                        //act_id = row.id;
                        var validateEnrollModal = utils.modal('审核报名项', function (ele) {
                            var html =  '<table class="table" id="validateEnrollTable"><thead><tr>' +
                                '<th data-field="" data-checkbox="true">选择</th>' +
                                '<th data-field="name" class="text-center">姓名</th>' +
//                                '<th data-field="contents" class="text-center" data-formatter="enrollContentsFormatter" data-events="operateErollEvents">内容</th>' +
                                '<th data-field="mobile" class="text-center">手机号</th>' +
                                '<th data-field="created_at" class="text-center">时间</th>' +
                                '<th data-field="details" class="text-center" data-formatter="enrollDetailsFormatter" data-events="operateErollEvents">详情</th>' +
                                '<th data-field="status" data-formatter="enrollStatusFormatter" class="text-center">状态</th>' +
                                '<th data-field="validateActions" class="text-center" data-formatter="enrollValidateFormatter" data-events="operateErollEvents">审核</th>' +
                                '</tr></thead></table>';
                            ele.find('.modal-body').html(html);
                            var enroll_table_option = {
                                toolbar:false,
                                search:false,
                                pagination: true,
                                sidePagination:'server',
                                pageSize:4,
                                showRefresh:false,
                                contentType: "application/x-www-form-urlencoded",
                                queryParams: function (query) {
                                    query['activities_id'] = act_id;
                                    return query;
                                },
                                url: '/web/enroll/list',
                            };

                            default_table_option = $.extend(default_table_option, enroll_table_option);
                            $('#validateEnrollTable').bootstrapTable(default_table_option);
                        }, ['确认'], function (res) {
                            if (res == 1) {
                                validateEnrollModal.modal('hide');
                            }
                        });
                    }
                });

            },
            'click .enrollCntView':function (e,value,row) {
                console.log(row);
//                var rule = eval('(' + row.activity.rule + ')');
//                var li_html='';
//                $.each(value,function(index,e){
//                    var li = '';
//                    if(index == 0){
//                        li = '<li data-target="#myCarousel" data-slide-to="0" class="active"></li>';
//                    }else{
//                        li =  '<li data-target="#myCarousel" data-slide-to="1"></li>';
//                    }
//                    li_html += li;
//                });
                var title = $(this).parents('.modal-content').find('.modal-title').text();
                var img_reg = new RegExp("<img","g");
                var video_reg = new RegExp("<video","g");
                value = value.replace(img_reg,'<img width="80%" ');
                value = value.replace(video_reg,'<video width="80%" ');
                var enrollContentModal = utils.modal('', function (ele) {
                    ele.find('.modal-body').html(value);
//                    var html = '<div class="pull-center">'+
//                        '<div id="myCarousel" class="carousel slide">'+
//                        <!-- 轮播（Carousel）指标 -->
//                        '<ol class="carousel-indicators">' +
//                        li_html+
//                        '</ol>'+
//                        <!-- 轮播（Carousel）项目 -->
//                        '<div class="carousel-inner" >';
//                    $.each(value,function (index,e) {
//                        var video_pattern = /^.*\.(mp4|ogg|webm|swf)$/i;
//                        var audio_pattern = /^.*\.(mp3|ogg)/i;
//                        var image_pattern = /^.*\.(jpg|gif|jpeg|png|bmp)$/i;
//                        var activable = index == 0 ? ' active' : '';
//
//                        if (e == 'has-no-video') {
//                            html += '<div><p>视频还未转码完成，暂时不能查看</p></div>';
//                        } else if (video_pattern.test(e)) {
//                            html+='<div class="item'+activable+'">'+
//                                '<video style="width: 85%;" controls="controls"><source src="' + e + '" type="video/mp4"></video>'+
//                                '</div>';
//                        } else if (image_pattern.test(e)) {
//                            html+='<div class="item'+activable+'" style="margin: 0 auto;">'+
//                                '<img src="'+e+'" alt="'+index+' slide" >'+
//                                '</div>'
//                        } else if (audio_pattern.test(e)) {
//                            html+='<div class="item'+activable+'">'+
//                                '<audio controls="controls"><source src="' + e + '" type="audio/mp3"></audio>'+
//                                '</div>';
//                        }
//                    });
//                    html+='</div>'+
//                        <!-- 轮播（Carousel）导航 &rsaquo;-->
//                        '<a class="carousel-control left" href="#myCarousel" data-slide="prev"><span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span></a>'+
//                        '<a class="carousel-control right" href="#myCarousel" data-slide="next"><span class="glyphicon glyphicon-menu-right" aria-hidden="true"></span></a>'+
//                        '</div>'+
//                        '</div>';
//                    ele.find('.modal-body').html(html);
                }, ['返回','确认'], function (res) {
                    if (res == 1) {
                        enrollContentModal.modal('hide');
                    }else if(res == 0){
                        if(title!='审核报名项'){
                            var enrollModal = utils.modal('查看报名信息', function (ele) {
                                var html = '<div><a class="btn btn-info btn-fill btn-wd pull-right mb15" href="/web/enroll/export?activity_id='+row.id+'" >导出数据</a><div>' +
                                    '<table class="table" id="enrollInfTable"><thead><tr>' +
                                    '<th data-field="name" class="text-center">姓名</th>' +
                                    '<th data-field="details" class="text-center" data-formatter="enrollContentsFormatter" data-events="operateErollEvents">内容</th>' +
                                    '<th data-field="mobile" class="text-center">手机号</th>' +
                                    '<th data-field="created_at" class="text-center">时间</th>' +
                                    '</tr></thead></table>';
                                ele.find('.modal-body').html(html);
                                var enroll_table_option = {
                                    toolbar:false,
                                    search:false,
                                    pagination: true,
                                    sidePagination:'server',
                                    pageSize:4,
                                    showRefresh:false,
                                    queryParams: function (query) {
                                        query['activities_id'] = row.activities_id;
                                        return query;
                                    },
                                    url: '/web/enroll/list',
                                };
                                default_table_option = $.extend(default_table_option, enroll_table_option);
                                $('#enrollInfTable').bootstrapTable(default_table_option);
                            }, ['确认'], function (res) {
                                if (res == 1) {
                                    enrollModal.modal('hide');
                                }
                            });
                        }else{
                            //act_id = row.activities_id;
                            var validateEnrollModal = utils.modal('审核报名项', function (ele) {
                                var html =  '<table class="table" id="validateEnrollTable"><thead><tr>' +
                                    '<th data-field="" data-checkbox="true">选择</th>' +
                                    '<th data-field="name" class="text-center">姓名</th>' +
                                    //                                '<th data-field="contents" class="text-center" data-formatter="enrollContentsFormatter" data-events="operateErollEvents">内容</th>' +
                                    '<th data-field="mobile" class="text-center">手机号</th>' +
                                    '<th data-field="created_at" class="text-center">时间</th>' +
                                    '<th data-field="details" class="text-center" data-formatter="enrollDetailsFormatter" data-events="operateErollEvents">详情</th>' +
                                    '<th data-field="status" data-formatter="enrollStatusFormatter" class="text-center">状态</th>' +
                                    '<th data-field="validateActions" class="text-center" data-formatter="enrollValidateFormatter" data-events="operateErollEvents">审核</th>' +
                                    '</tr></thead></table>';
                                ele.find('.modal-body').html(html);
                                var enroll_table_option = {
                                    toolbar:false,
                                    search:false,
                                    pagination: true,
                                    sidePagination:'server',
                                    pageSize:4,
                                    showRefresh:false,
                                    contentType: "application/x-www-form-urlencoded",
                                    queryParams: function (query) {
                                        query['activities_id'] = act_id;
                                        return query;
                                    },
                                    url: '/web/enroll/list',
                                };

                                default_table_option = $.extend(default_table_option, enroll_table_option);
                                $('#validateEnrollTable').bootstrapTable(default_table_option);
                            }, ['确认'], function (res) {
                                if (res == 1) {
                                    validateEnrollModal.modal('hide');
                                }
                            });
                        }
                    }
                });
            },
            //审核通过
            'click .validate':function (e,value,row) {
                if(row.status == 1){
                    utils.showNotification('审核已通过，不可重复审核！',3);
                    return false;
                }
                var check_flag = {{\App\Models\Enroll\Enroll::CHECK_PASS}};
                $.post('/web/enroll/edit',{groupid:groupid,id:row.id,act_id:act_id,status:check_flag},function (res) {
                    if (res.code == 0){
                        utils.showNotification('操作成功',2);
                        $('#validateEnrollTable').bootstrapTable('refresh');
                    }else {
                        utils.showNotification(res.message,3);
                    }

                })
            },
            //审核不通过
            'click .unvalidate':function (e,value,row) {
                var check_flag = {{\App\Models\Enroll\Enroll::CHECK_NO_PASS}};
                $.post('/web/enroll/edit',{groupid:groupid,id:row.id,act_id:act_id,status:check_flag},function (res) {
                    if (res.code == 0){
                        utils.showNotification('操作成功',2);
                        $('#validateEnrollTable').bootstrapTable('refresh');
                    }else {
                        utils.showNotification('操作失败',3);
                    }

                })
            }
        };
        var act_id ;//全局活动id
        var groupid;//全局分组id
        window.operateEvents = {
            'click .duijiang':function (e,value,row) {
                window.location.href = "/web/activityRecords/index?activity_id="+row.id;
            },
            'click .pause':function (e,value,row) {
                var isPause = row.isPause == 1?0:1;
                $.post('/web/activity/edit',{id:row.id,isPause:isPause},function (res) {
                    console.log('---------------');
                    console.log(row.id);
                    console.log(isPause);
                    console.log(res);
                    console.log('---------------');
                    if (res.code == 0){
                        utils.showNotification('操作成功',2);
                        $('#bootstrap-table-container').bootstrapTable('refresh');
                    }else {
                        utils.showNotification('操作失败',3);
                    }

                })

            },
            'click .delete':function (e,value,row) {
                var bt = document.body.querySelector('#bootstrap-table-container');
                var event = new CustomEvent("table-delete-item", { "detail": [row.id] });
                bt.dispatchEvent(event);
            },
            'click .stock':function (e,value,row) {
                var stockModal = utils.modal('奖品库存', function (ele) {
                    var html = '<table class="table" id="prizeStockTable"><thead><tr><th data-field="prize.name" class="text-center" data-formatter="prizeNameFormatter">奖品名称</th><th data-field="stock_limit" class="text-center">添加总数</th><th data-field="awarding_number" class="text-center">兑奖成功</th><th data-field="not_awarding_number" class="text-center">未兑奖</th><th data-field="surplus" class="text-center">本活动剩余</th></tr></thead></table>';
                    ele.find('.modal-body').html(html);
                    var table_option = {
                        toolbar:false,
                        search:false,
                        pagination: false,
                        showRefresh:false,
                        queryParams: function (query) {
                            query['id'] = row.id;
                            return query;
                        },
                        url: '/web/activity/prizeStock'
                    }
                    default_table_option = $.extend(default_table_option, table_option);
                    $('#prizeStockTable').bootstrapTable(default_table_option);
                }, ['确认'], function (res) {
                    if (res == 1) {
                        stockModal.modal('hide');
                    }
                });
            },
            //二维码
            'click .view':function (e,value,row) {
                var qrcodeModal = utils.modal('应用场景',function (ele) {
                    console.log(row.id);
                    $.get('/web/activity/qrcode',{id:row.id},function (res) {
                        ele.find('.modal-body').html(res);
                    })
                },['确认'],{style:'modal-width900'},function () {
                    qrcodeModal.modal('hide');
                });
            },
            'click .config':function (e,value) {
                var appSceneModal =  utils.modal('应用场景',function (ele) {
                    $.get('/web/activity/app_scene',function (res) {
                        ele.find('.modal-body').html(res);
                    })
                },['确认'],{style:'modal-appScene'},function () {
                    appSceneModal.modal('hide');
                });
            },
            //报名信息
            'click .enrollInfo':function(e,value,row){
                console.log(row);
//                <th data-field="enrollPay" class="text-center" data-formatter="enrollPayFormatter">支付</th>
                var enrollModal = utils.modal('查看报名信息', function (ele) {
                    var html = '<div><a class="btn btn-info btn-fill btn-wd pull-right mb15" href="/web/enroll/export?activity_id='+row.id+'" >导出数据</a><div>' +
                        '<table class="table" id="enrollInfTable"><thead><tr>' +
                        '<th data-field="name" class="text-center">姓名</th>' +
                        '<th data-field="details" class="text-center" data-formatter="enrollContentsFormatter" data-events="operateErollEvents">内容</th>' +
                        '<th data-field="mobile" class="text-center">手机号</th>' +
                        '<th data-field="created_at" class="text-center">时间</th>' +
                        '</tr></thead></table>';
                    ele.find('.modal-body').html(html);
                    var enroll_table_option = {
                        toolbar:false,
                        search:false,
                        pagination: true,
                        sidePagination:'server',
                        pageSize:4,
                        showRefresh:false,
                        queryParams: function (query) {
                            query['activities_id'] = row.id;
                            return query;
                        },
                        url: '/web/enroll/list',
                    };
                    default_table_option = $.extend(default_table_option, enroll_table_option);
                    $('#enrollInfTable').bootstrapTable(default_table_option);
                }, ['确认'], function (res) {
                    if (res == 1) {
                        enrollModal.modal('hide');
                    }
                });
            },
            //投票审核报名
            'click .validateEroll':function(e,value,row){
                act_id = row.id;
//                <th data-field="enrollPay" class="text-center" data-formatter="enrollPayFormatter">支付</th>
                var validateEnrollModal = utils.modal('审核报名项', function (ele) {
//                     '<div><button class="btn btn-info btn-fill btn-wd pull-left mb15" onclick="checkAllPass(this)">批量审核通过</button><button class="btn btn-info btn-fill btn-wd pull-left mb15 mgl5" onclick="checkAllNotPass(this)" >批量审核不通过</button><div>' +
                    var html =  '<table class="table" id="validateEnrollTable"><thead><tr>' +
                        '<th data-field="" data-checkbox="true">选择</th>' +
                        '<th data-field="name" class="text-center">姓名</th>' +
//                        '<th data-field="contents" class="text-center" data-formatter="enrollContentsFormatter" data-events="operateErollEvents">内容</th>' +
                        '<th data-field="mobile" class="text-center">手机号</th>' +
                        '<th data-field="created_at" class="text-center">时间</th>' +
                        '<th data-field="details" class="text-center" data-formatter="enrollDetailsFormatter" data-events="operateErollEvents">详情</th>' +
                        '<th data-field="status" data-formatter="enrollStatusFormatter" class="text-center">状态</th>' +
                        '<th data-field="validateActions" class="text-center" data-formatter="enrollValidateFormatter" data-events="operateErollEvents">审核</th>' +
                        '</tr></thead></table>';
                    ele.find('.modal-body').html(html);
                    var enroll_table_option = {
                        toolbar:false,
                        search:false,
                        pagination: true,
                        sidePagination:'server',
                        pageSize:4,
                        showRefresh:false,
                        contentType: "application/x-www-form-urlencoded",
                        queryParams: function (query) {
                            query['activities_id'] = row.id;
                            return query;
                        },
                        url: '/web/enroll/list',
                    };

                    default_table_option = $.extend(default_table_option, enroll_table_option);
                    $('#validateEnrollTable').bootstrapTable(default_table_option);
                }, ['确认'], function (res) {
                    if (res == 1) {
                        validateEnrollModal.modal('hide');
                    }
                });
            },
            //wenzhen add by 2017/8/18
            'click .table-action.edit': function(e,value,row){
                console.log(row.model.rule);
                e.preventDefault();
                e.stopPropagation();
                var newModels = ['roulette','shaking','quiz','scratch','golden-eggs','lucky-bag','open-red-packet','gifts','chopHand','exponent','takebook','alasd','lucky-card','sudoku','balance','lottory-box','team-pk','money-tree','iantern','catch-guost','climb-thegreatwall','collect-sticker','eat-chicken','invite-bonus','caizhangdie','chaikuaidi','dadishu','check-in','prize-code','plane-wars'];
                if(newModels.indexOf(row.model.rule)>-1){
                    if(row.model.rule=='quiz'){
                        location.href = '/web/activity/'+row.model.rule+'?category='+row.category+'&model_id='+row.model_id+'&template_id='+row.template_id+'&activity_id='+row.id+'&model_rule='+row.model.rule+'#/1/'+row.id;
                    }else if(row.model.rule == 'prize-code'){
                        location.href = '/web/activity/edit?id='+row.id;
                    }else{
                        location.href = '/web/activity/'+row.model.rule+'?category='+row.category+'&model_id='+row.model_id+'&template_id='+row.template_id+'&activity_id='+row.id+'&model_rule='+row.model.rule;
                    }
                }else{
                    location.href = '/web/activity/edit?id='+row.id;
                }
            },
            'click .copy': function (e, value, row) {
                if (!row.id) {
                    return;
                }

                $.post('/web-api/copy/' + row.id).then(function (data, status, xhr) {
                    if (data.code == 200) {
                        utils.showNotification('复制成功', 2);
                        window.location.reload();
                    } else {
                        utils.showNotification('复制失败', 3);
                    }
                });
            },
            'click .weight': function (e, value, row){
                if (!row.id) {
                    return '';
                }
                var enrollModal = utils.modal('修改权重', function (ele) {
                    var html = '<div><span style="color: #9A9A9A;">权重：</span><input id="weight" type="text" data-field="weight" style="color: #565656;width: 361px;border: 1px solid #E3E3E3;padding: 8px 12px;height: 40px;border-radius: 4px;" value="'+row.weight+'" /><div>';
                    ele.find('.modal-body').html(html);
                }, ['确认'], function (res) {
                    if (res == 1) {
                        var weight = $("#weight").val();
                        if(isNaN(weight) || ''==weight){
                            utils.showNotification('请输入数字',3);
                            return false;
                        }
                        $.ajax({
                            type: 'PATCH',
                            url: '/web/activity/weight',
                            dataType: 'json',
                            data:{id:row.id,weight:weight},
                        }).success(function(data){
                            console.log(data);
                            if(data.code==200){
                                utils.showNotification('操作成功',2);
                                window.location.reload();
                            }else{
                                utils.showNotification('操作失败',3);
                            }
                        }).error(function(data){
                            console.log(data);
                        });
                    }
                });
            }
        };

        //批量审核通过
        function checkAllPass(obj){
            var oo = $('input[name="btSelectItem"]:checked');
            if(oo.length == 0){
                utils.showNotification('请选择操作项',2);
                return ;
            }
            var ids = [];
            oo.each(function () {
                ids.push($(this).val());
            });
            var check_flag = {{\App\Models\Enroll\Enroll::CHECK_PASS}};
            $.post('/web/enroll/editbatch',{id:ids,act_id:act_id,status:check_flag},function (res) {
                if (res.code == 0){
                    utils.showNotification('操作成功',2);
                    $('#validateEnrollTable').bootstrapTable('refresh');
                }else {
                    utils.showNotification('操作失败',3);
                }

            })
        }
        //批量审核未通过
        function checkAllNotPass(obj){
            var oo = $('input[name="btSelectItem"]:checked');
            if(oo.length == 0){
                utils.showNotification('请选择操作项',2);
                return ;
            }
            var ids = [];
            oo.each(function () {
                ids.push($(this).val());
            });
            var check_flag = {{\App\Models\Enroll\Enroll::CHECK_NO_PASS}};
            $.post('/web/enroll/editbatch',{id:ids,act_id:act_id,status:check_flag},function (res) {
                if (res.code == 0){
                    utils.showNotification('操作成功',2);
                    $('#validateEnrollTable').bootstrapTable('refresh');
                }else {
                    utils.showNotification('操作失败',3);
                }

            })
        }
        function prizeNameFormatter(value,row) {
            return row.prize.name;
        }
        //查看报名信息列表formatter
        //内容
        function enrollContentsFormatter(value,row){
            var str;
            if(row.content = null){
                str='无内容';
            }else{
                str='<a class="btn btn-simple btn-warning btn-icon table-action enrollCntView">查看</a>'
            }
            return str;
        }
        //详情
        function enrollDetailsFormatter(value,row){
            var str;
            if(row.detail = null){
                str='无内容';
            }else{
                str='<a class="btn btn-simple btn-warning btn-icon table-action enrollDetailsView">查看</a>'
            }
            return str;
        }
        //支付
        function enrollPayFormatter(value,row) {
            return row.enrollPay+'元';
        }
        function enrollStatusFormatter(value,row) {
            var status;
            if(row.status == {{\App\Models\Enroll\Enroll::CHECK_NULL}}){
                status = '未审核';
            }else if(row.status == {{\App\Models\Enroll\Enroll::CHECK_PASS}}){
                status = '通过';
            }else if(row.status == {{\App\Models\Enroll\Enroll::CHECK_NO_PASS}}){
                status = '未通过';
            }
            return status;
        }
        //报名审核
        function enrollValidateFormatter(value,row,index) {
            var dropdown_id = 'dropdown_'+new Date().getTime();
            var validateActions = [];
            var groups = row.groups;
            var rowData = [
                '<div class="btn-group">' +
                '<a  id="'+dropdown_id+'" aria-haspopup="true"  aria-expanded="false" data-toggle="dropdown" class="btn btn-simple btn-danger btn-icon table-action dropdown-toggle more" href="javascript:void(0)">',
                '审核<i class="fa fa-sort-desc"></i>',
                '</a>',
                '<ul class="dropdown-menu td-actions-dropdown" role="menu" aria-labelledby="'+dropdown_id+'">',
            ];
            if(groups.length == 0){
                rowData.push('<li><a href="#" class="validate">通过</a></li>' );
                groupid = null;
            }else{
                for(var i=0; i< groups.length; i++){
                    rowData.push('<li><a href="#" class="group" onclick="checkGroup(this)" data-rowstatus="'+row.status+'" data-rowid="'+row.id+'"  data-groupid="'+groups[i]["id"]+'">'+groups[i]["title"]+'</a></li>' );
                }
            }
            rowData.push('</ul>' );
            rowData.push('</div>' );
            validateActions.push(rowData .join(''));

            return validateActions.join('');
        }
        function checkGroup(obj) {
            groupid = $(obj).data('groupid');
            var row_id = $(obj).data('rowid');
            var status = $(obj).data('rowstatus');
            if(status == 1){
                utils.showNotification('审核已通过，不可重复审核！',3);
                return false;
            }
            var check_flag = {{\App\Models\Enroll\Enroll::CHECK_PASS}};
            $.post('/web/enroll/edit',{groupid:groupid,id:row_id,act_id:act_id,status:check_flag},function (res) {
                if (res.code == 0){
                    utils.showNotification('操作成功',2);
                    $('#validateEnrollTable').bootstrapTable('refresh');
                }else {
                    utils.showNotification(res.message,3);
                }

            })
        }
        function operateFormatter(value,row,index) {
            var dropdown_id = 'dropdown_'+new Date().getTime();
            var actions = [];
            if (row.model.rule=='redpack_rain'){
                if(row.category == 1){
                    actions.push('<a rel="tooltip" title="活动二维码" class="btn btn-simple btn-info btn-icon table-action view" href="javascript:void(0)">二维码</a>');
                }else {
                    actions.push('<a rel="tooltip" title="活动二维码" class="btn btn-simple btn-info btn-icon table-action view" href="javascript:void(0)">二维码</a>');
                    actions.push('<a rel="tooltip" title="兑奖" class="btn btn-simple btn-info btn-icon table-action duijiang" href="javascript:void(0)">兑奖</a>');
                }
                actions.push( [
                    '<a rel="tooltip" title="编辑" class="btn btn-simple btn-warning btn-icon table-action edit" href="/web/activity/edit?id='+row.id+'">',
                    '编辑',
                    '</a>',
                    '<div class="btn-group"><a  id="'+dropdown_id+'" aria-haspopup="true"  aria-expanded="false" data-toggle="dropdown" class="btn btn-simple btn-danger btn-icon table-action dropdown-toggle more" href="javascript:void(0)">',
                    '<i class="fa fa-ellipsis-h"></i>',
                    '</a>',
                    '<ul class="dropdown-menu td-actions-dropdown" role="menu" aria-labelledby="'+dropdown_id+'">',
                    (row.category ==1?'<li><a href="#" class="duijiang">兑奖</a></li>':''),
                    (row.category ==2?'<li><a href="#" class="config">配置</a></li>':''),
                    '<li><a href="#" class="pause">'+(row.isPause == 1?'开始':'暂停')+'</a></li>',
                    //'<li><a href="#" class="">报表</a></li>',
                    '<li><a href="#" class="delete">删除</a></li>',
                    '<li><a href="#" class="stock">库存</a></li>',
                    '</ul>' ,
                    '</div>',
                ].join(''));
            }else{
                if (row.model.rule=='shaking'||row.model.rule=='roulette'||row.model.rule=='scratch'||row.model.rule=='golden-eggs') {
                    actions.push('<a rel="tooltip" title="兑奖" class="btn btn-simple btn-info btn-icon table-action duijiang" href="javascript:void(0)">兑奖</a>');
                }
                if(row.isPause==1){
                    if(row.model.rule=='enroll'){
                        actions.push('<a rel="tooltip" title="报名信息" class="btn btn-simple btn-info btn-icon table-action enrollInfo" href="#">报名信息</a>');
                    }
                    actions.push('<a rel="tooltip" title="编辑" class="btn btn-simple btn-warning btn-icon table-action edit" href="/web/activity/edit?id='+row.id+'">编辑</a>');
                    actions.push('<a rel="tooltip" href="#" class="btn btn-simple btn-warning btn-icon table-action delete">删除</a>');

//                    if(!(row.model.rule=='quiz'&&moment(row.startTime).unix()<moment().unix()&&moment().unix()<moment(row.endTime).unix())){
//                        actions.push('<a rel="tooltip" title="编辑" class="btn btn-simple btn-warning btn-icon table-action edit" href="/web/activity/edit?id='+row.id+'">编辑</a>');
//                    }
//                }else if(moment(row.endTime).unix()<moment().unix()&&row.model.rule=='vote'){
                }else if(row.model.rule=='vote'){
                    actions.push('<a rel="tooltip" title="导出结果" class="btn btn-simple btn-info btn-icon table-action " href="/web/vote/getValidationData?activity_id='+row.id+'">导出结果</a>');
                }else if(row.model.rule=='enroll'){
                    actions.push('<a rel="tooltip" title="报名信息" class="btn btn-simple btn-info btn-icon table-action enrollInfo" href="#">报名信息</a>');
                }
                actions.push( [
                    '<a rel="tooltip" title="活动二维码" class="btn btn-simple btn-info btn-icon table-action view" href="javascript:void(0)">',
                    '二维码',
                    '</a>',
                    '<div class="btn-group"><a  id="'+dropdown_id+'" aria-haspopup="true"  aria-expanded="false" data-toggle="dropdown" class="btn btn-simple btn-danger btn-icon table-action dropdown-toggle more" href="javascript:void(0)">',
                    '<i class="fa fa-ellipsis-h"></i>',
                    '</a>',
                    '<ul class="dropdown-menu td-actions-dropdown" role="menu" aria-labelledby="'+dropdown_id+'">',
                    '<li><a href="#" class="pause">'+(row.isPause == 1?'开始':'暂停')+'</a></li>',
                    //'<li><a href="#" class="">报表</a></li>',
                ].join(''));
                if(row.model.rule=='vote'){
                    var actRule = eval('(' + row.rule + ')');
                    var relevanceEnrollLink = '';
                    var bigScreen = '';console.log();
                    var voteList = '';
                    if(actRule.hasOwnProperty('relevanceEnrollOn') && actRule.relevanceEnrollOn == 'on'){
                        relevanceEnrollLink = '<li><a  href="javascript:void(0)" class="validateEroll">审核报名</a></li>';
                    }
                    if(row.template.template == 'default'){
                        bigScreen = '<li><a target="_blank"  href="/api/activity/votedp?activity_id='+row.id+'" class="">大屏</a></li>';
                    }

//                    if(row.template.template == 'vote-screen' || row.template.template == 'multiple-vote'){
                        voteList = '<li><a href="/web/vote/voteRecord?activity_id='+row.id+'" class="">投票记录</a></li>';
//                    }
                    actions.push( [
                        '<li><a href="/web/vote/showRecordViews?activity_id='+row.id+'" class="">数据</a></li>',
                        bigScreen,
                        voteList,
                        relevanceEnrollLink,
//                        '</ul>' ,
//                        '</div>',
                    ].join(''));
                }else if(row.model.rule=='enroll'){
//                    actions.push( [
//                        //'<li><a href="javascript:void(0)" >报表</a></li>',
//                        '</ul>' ,
//                        '</div>',
//                    ].join(''));
                }
                //wenzhen add by 2017/8/28
                if(row.model.rule=='quiz'){
                    actions.push([
                        '<li><a href="/web/activity/quiz?category=' + row.category + '&model_id=' + row.model_id + '&template_id=' + row.template_id + '&activity_id=' + row.id + '#/export" class="export">数据导出</a></li>',
                    ].join(''));
                }
                actions.push('<li><a rel="tooltip" title="复制活动" class="copy" href="javascript:void(0)">复制</a></li>');
                actions.push('<li><a rel="tooltip" title="权重修改" class="weight" href="javascript:void(0)">权重</a></li>',
                    '</ul>',
                    '</div>');
//              actions.push('<a rel="tooltip" title="活动二维码" class="btn btn-simple btn-info btn-icon table-action view" href="javascript:void(0)"><i class="fa fa-qrcode"></i></a>');
            }

            return actions.join('');
        }
        $('#bootstrap-table-container').on('post-body.bs.table',function () {
            $('[rel="tooltip"]').tooltip();
        });

        $('#activity-list').perfectScrollbar('destroy');
    </script>
@endsection